
var BattleBullet = cc.Node.extend({

    SPEED : 600, // 像素每秒

    side : 0,    // 站位 0:下 1:上
	image : null,

    ctor : function (side, cx, cy) {
		this._super();

    	var file = 'res/battle/bullet.png';
        this.image = cc.Sprite.create(file);
        //this.image.setScale(0.5);
    	this.addChild(this.image);

        this.setCellPos(cx, cy, side);
        this.setSide(side);

        // 动画
        //this.aniInit(true);
        //this.aniIdle();
	},

    // 设置格子坐标
    setCellPos : function (cx, cy, side) {
        // 子弹起始位置偏移半格
        var p = helper.posCell2Scene(cx, cy, side);
        
        if (side == 0) {
            p.y = p.y + helper.CELL_SIZE / 2;
        } else {
            p.y = p.y - helper.CELL_SIZE / 2;
        }
        cc.dump(p)
        this.setPosition( p );
    },

    setSide : function (side) {
        if (side == 1) {
            this.setScaleY(-1);
        }
        this.side = side;
    },

    // 移动, 参数坐标相对于游戏场景, BattleLayer
    moveTo :function (px, py, overFunc, target) {
        var p = this.getPosition();
        var length = Math.sqrt( (px - p.x) * (px - p.x) + (py - p.y) * (py - p.y) );
        var time = length / this.SPEED;
        var move = cc.MoveTo.create(time, {x:px, y:py});    // 移动
        var func = cc.CallFunc.create(overFunc, target);         // 结束回调
        var seq = cc.Sequence.create(move, func);
        this.runAction(seq);
    },

});

